package com.example.newnoke.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.view.View;

import com.example.newnoke.MainActivity;
import com.example.newnoke.R;
import com.example.newnoke.data.LoginData;
import com.example.newnoke.databinding.ActivityLoginBinding;
import com.example.newnoke.mvp.presenter.LoginPresenter;
import com.example.newnoke.mvp.view.ILoginV;
import com.example.newnoke.utils.API;
import com.geya.jbase.baseactivity.BaseDetailsActivity;
import com.geya.jbase.constant.RequestType;
import com.geya.jbase.uiview.LoadDialog;
import com.geya.jbase.uiview.ToastUtil;

import java.util.HashMap;

public class LoginActivity extends BaseDetailsActivity<LoginPresenter> implements ILoginV {

    private ActivityLoginBinding mBinding;

    @Override
    public LoginPresenter newPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    public void init() {
    mBinding.login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (mBinding.zhanghao.getText().toString().isEmpty()){
                ToastUtil.showShort("请输入账号");
                return;
            }
            if (mBinding.mima.getText().toString().isEmpty()){
                ToastUtil.showShort("请输入密码");
                return;
            }
            LoadDialog.show(LoginActivity.this);
            HashMap<String, String> map = new HashMap<>();
            map.put("name", mBinding.zhanghao.getText().toString());//13593236985
            map.put("password",  mBinding.mima.getText().toString());//13597563214

            mPresenter.accessServers(RequestType.OKGO_POST, API.LOGIN, LoginData.class, map);
//            startActivity(new Intent(LoginActivity.this,MainActivity.class));
    }
    });

    mBinding.zhuce.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(new Intent(LoginActivity.this,ZhuCeActivity.class));

        }
    });
       mBinding.zh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(new Intent(LoginActivity.this,ZHMMActivity.class));

        }
    });


    }

    @Override
    public void setContentView() {
        mImmersionBar.statusBarColor(R.color.wu);
        mImmersionBar.init();
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_login);

    }

    @Override
    public void login(LoginData.DataBean.PopInfoBean data) {
        if (data!=null){
            startActivity(new Intent(LoginActivity.this,MainActivity.class)
                    .putExtra("title",data.getTitle())
                    .putExtra("topic",data.getTopic())
                    .putExtra("desc",data.getDesc())
                    .putExtra("show",true)
            );
        }else {
            startActivity(new Intent(LoginActivity.this,MainActivity.class));
        }

        finish();
    }



    @Override
    public void showMsg(String msg) {

    }
}
